Determines if the file pointer has reached the end of a file.
ファイルポインタがファイル末尾に到達したかを確認します。
Eof (intexpression As Integer)
Eof (intexpression As Integer)
Bool
ブール型
Intexpression: Any integer expression that evaluates to the number of an open file.
Intexpression:オープン済みファイルを指定する整数表式。
Use EOF to avoid errors when you attempt to get input past the end of a file. When you use the Input or Get statement to read from a file, the file pointer is advanced by the number of bytes read. When the end of a file is reached, EOF returns the value "True" (-1).
ファイルの末尾を超えてデータを書き込もうとするとエラーが発生しますが、これを防止するには EOF 関数を使用できます。ファイル中のデータを Input ないし Get ステートメントを用いて読み取る場合は、読み込んだデータのバイト数だけファイルポインタの値が更新されます。そしてファイル末尾に到達すると、EOF 関数は「True」(-1) を返します。
Sub ExampleWorkWithAFile
Sub ExampleWorkWithAFile
Dim iNumber As Integer
Dim iNumber As Integer
Dim sLine As String
Dim sLine As String
Dim aFile As String
Dim aFile As String
Dim sMsg as String
Dim sMsg as String
aFile = "c:\data.txt"
aFile = "c:\data.txt"
iNumber = Freefile
iNumber = Freefile
Open aFile For Output As #iNumber
Open aFile For Output As #iNumber
Print #iNumber, "First line of text"
Print #iNumber, "First line of text"
Print #iNumber, "Another line of text"
Print #iNumber, "Another line of text"
Close #iNumber
Close #iNumber
iNumber = Freefile
iNumber = Freefile
Open aFile For Input As iNumber
Open aFile For Input As iNumber
While not eof(iNumber)
While not eof(iNumber)
Line Input #iNumber, sLine
Line Input #iNumber, sLine
If sLine <>"" then
If sLine <>"" then
sMsg = sMsg & sLine & chr(13)
sMsg = sMsg & sLine & chr(13)
end if
end if
wend
Wend
Close #iNumber
Close #iNumber
Msgbox sMsg
Msgbox sMsg
End Sub
End Sub